

// pages/applyform.ts
const util = require('./../utils/util');



const computedBehavior = require("miniprogram-computed").behavior;

Page({

  behaviors: [computedBehavior],
  /**
   * 页面的初始数据
   */
  data: {
    ringImgCache:'',
    canvasRing: {},
    vary_width: wx.getSystemInfoSync().windowWidth * 0.5,
    process: 67,
    activeTab: 1,
    kucunTotalWeight: '100kg',
    modified_goods:[],
    taskId:'',
    pageData:{
      memo:'',
      memoModify:''
    },
    kucun_goods: [
      { "key": "maojin", "name": "毛巾", value: 15 },
      {"key":"yujin","name":"浴巾",value:0},
      {"key":"beizhao","name":"被罩",value:0},
      { "key": "chuangdan", "name": "床单", value: 11 },
      { "key": "didian", "name": "地垫", value: 12 },
      { "key": "beizhu", "name": "备注", value: "xxx" }
    ],
  },
  changeKucun(event: any) {
    var goods = event.target.dataset['goods'];
      var rows = this.data.modified_goods.filter((r: any) => r.name == goods)
      if (rows.length > 0) {
        rows[0].value = event.detail;
      } else {
        this.data.modified_goods.push({ "name": goods, "value": event.detail })
      }
      
      this.setData({
        modified_goods: this.data.modified_goods
      })
      console.log(this.data.modified_goods[goods])
    },

    saveData() {
      // var repository = this.data.kucun_goods;
      if(this.data.modified_goods.length>0) {
        for(const i in this.data.modified_goods) {
          var willUpdateRow = this.data.modified_goods[i];
          for (const j in this.data.kucun_goods) {
            
            if(willUpdateRow.name==this.data.kucun_goods[j].name) {
              this.data.kucun_goods[j].value = willUpdateRow.value;
              continue;
            }
          }
        }
      }

      this.setData({
        kucun_goods: this.data.kucun_goods
      }); 
      this.setData({"tmpmap":{}}); //不可删除,用于计算属性refresh
      // wx.clearStorage("ringImgCache")
      util.request_json_post('/api/hotel-recycle/updateTask',this.data.kucun_goods).then((res) => {
        
      },(err) => {
  

      })
    },
      
  methods: {
    changeTab() {
      this.setData({'ringImgCache': wx.getStorageSync('ringcache')})
    }

  },
  computed: {
    kucunItemCount(data) {
      data.tmpmap = {}
      data.kucun_goods.forEach((row:any) => { data.tmpmap[row.name] = row });
      return data.tmpmap
    }
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
     
    this.setData({'ringImgCache': wx.getStorageSync('ringcache')})
  },

  onPageScroll() {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
      
    this.initRing()
     
    },
    initRing() {
      //···第一个圆环···
    const canvasRing = this.selectComponent("#canvasRing");
    var that  = this;
    canvasRing.setData({
        value: this.data.process,
        title: '约完成'+this.data.kucunTotalWeight,
        subTitle:'距离上门'+this.data.process+'%'
      });
    
    canvasRing.drawCanvasRing(); //如果有定时器 就把它放定时器里面
    
    
    }
    
    
});